package cn.zzuisa.deutsch.controller;

import cn.zzuisa.deutsch.base.Constant;
import cn.zzuisa.deutsch.base.R;
import cn.zzuisa.deutsch.entity.Member;
import org.jsoup.Connection;
import org.jsoup.Jsoup;
import org.jsoup.helper.StringUtil;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.select.Elements;
import org.springframework.http.HttpRequest;
import org.springframework.http.server.ServletServerHttpRequest;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@SuppressWarnings("none")
public class test {
    public static void main(String[] args) {
        String word = "gehen";
        String starter = "http://www.godic.net/dicts/de/" + word.replaceAll("\\+","%20");
        Document start = null;
        try {
            start = Jsoup.connect(starter)
                    .timeout(Constant.TIMEOUT).get();
            godicController.Dict dict = new godicController.Dict();
//            String url = "http://www.godic.net/Dicts/de/tab-detail/expcg";
//            Document doc = null;
//            Connection con = Jsoup.connect(url);
//            Map<String, String> form = new HashMap<>();
//            String status = start.select("#page-status").val();
//            System.out.println("status:"+status);
//            form.put("status", status);
//            con.data(form);
//            doc = con.post();
//            doc.select("#cg-speak").remove();
//            doc.select("#sp-cg-category").remove();
//            doc.select("#sp-cg-category-selector").remove();
//            doc.select("ul").remove();
//            System.out.println(doc.html());
        } catch (Exception e) {
        }

//        Elements script = doc.getElementsByTag("script");
//        script.remove();
//        Elements content = doc.select("#ExpFCChild");
//        String img = "";
//        String ver = "";
//        if (doc.select("#ExpFCChild img").size() > 0) {
//            img = doc.select("#ExpFCChild img").get(0).toString() + "<br>";
//            Elements element = doc.select("#translate");
//            System.out.println("size:"+element.size());
//            if (element.size() > 0) {
//                 ver = element.get(0).toString();
//                System.out.println(ver);
//                if (!StringUtil.isBlank(ver)) {
//                    ver = "<div id=\"cg_table\" class=\"cg_de\">" + ver + "</div>";
//                }
//                dict.setVer(ver != null ? ver : "");
//            }
//        }
//        System.out.println(ver);
    }
    public static String stringToAscii(String value)
    {
        StringBuffer sbu = new StringBuffer();
        char[] chars = value.toCharArray();
        for (int i = 0; i < chars.length; i++) {
            if(i != chars.length - 1)
            {
                sbu.append((int)chars[i]).append(",");
            }
            else {
                sbu.append((int)chars[i]);
            }
        }
        return sbu.toString();

    }
}
